package com.example.sunming.thread;

public class TestThreadLocal {
    static class MyThread extends Thread {
        private static ThreadLocal<Integer> threadLocal = new ThreadLocal<>();

        @Override
        public void run() {
            super.run();
            for (int i = 0; i < 3; i++) {
                threadLocal.set(i);
                System.out.println(getName() + "threadLocal.get()=" + threadLocal.get());
            }
        }
    }

    public static void main(String[] args) {
        MyThread threadA = new MyThread();
        threadA.setName("threadA");
        MyThread threadB = new MyThread();
        threadB.setName("threadB");
        threadA.start();
        threadB.start();
    }
}
